package com.getpebble.android.main.fragment;

import android.app.Fragment;
import android.os.Bundle;
import android.os.Looper;
import com.getpebble.android.R;
import com.getpebble.android.connection.ConnectionManagerFragment;
import com.getpebble.android.main.sections.appstore.constants.AppStoreConstants.StoreType;
import com.getpebble.android.main.sections.appstore.fragment.AppStoreFragment;
import com.getpebble.android.main.sections.appstore.fragment.NoConnectivityFragment;
import com.getpebble.android.main.sections.developer.DeveloperFragment;
import com.getpebble.android.main.sections.mypebble.fragment.MyPebbleFragment;
import com.getpebble.android.main.sections.notifications.NotificationSettingsFragment;
import com.getpebble.android.main.sections.settings.fragment.SettingsFragment;
import com.getpebble.android.main.sections.support.fragment.SupportFragment;
import com.sun.mail.iap.Response;
import com.sun.mail.imap.protocol.ListInfo;
import com.sun.mail.smtp.SMTPMessage;
import java.util.ArrayList;
import java.util.HashMap;

public class FragmentMetaData {
    private static int DEVELOPER_DRAWER_INDEX = 5;
    private static ArrayList<FragmentData> sDataByDrawerIndex;
    private static HashMap<FragmentType, FragmentData> sDataByType;

    static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] $SwitchMap$com$getpebble$android$main$fragment$FragmentMetaData$FragmentType = new int[FragmentType.values().length];

        static {
            try {
                $SwitchMap$com$getpebble$android$main$fragment$FragmentMetaData$FragmentType[FragmentType.MY_PEBBLE.ordinal()] = 1;
            } catch (NoSuchFieldError e) {
            }
            try {
                $SwitchMap$com$getpebble$android$main$fragment$FragmentMetaData$FragmentType[FragmentType.APP_STORE_FACES.ordinal()] = 2;
            } catch (NoSuchFieldError e2) {
            }
            try {
                $SwitchMap$com$getpebble$android$main$fragment$FragmentMetaData$FragmentType[FragmentType.APP_STORE_APPS.ordinal()] = 3;
            } catch (NoSuchFieldError e3) {
            }
            try {
                $SwitchMap$com$getpebble$android$main$fragment$FragmentMetaData$FragmentType[FragmentType.DEVELOPER.ordinal()] = 4;
            } catch (NoSuchFieldError e4) {
            }
            try {
                $SwitchMap$com$getpebble$android$main$fragment$FragmentMetaData$FragmentType[FragmentType.SETTINGS.ordinal()] = 5;
            } catch (NoSuchFieldError e5) {
            }
            try {
                $SwitchMap$com$getpebble$android$main$fragment$FragmentMetaData$FragmentType[FragmentType.SUPPORT.ordinal()] = 6;
            } catch (NoSuchFieldError e6) {
            }
            try {
                $SwitchMap$com$getpebble$android$main$fragment$FragmentMetaData$FragmentType[FragmentType.APP_STORE_APPLICATION.ordinal()] = 7;
            } catch (NoSuchFieldError e7) {
            }
            try {
                $SwitchMap$com$getpebble$android$main$fragment$FragmentMetaData$FragmentType[FragmentType.APP_STORE_DEVELOPER.ordinal()] = 8;
            } catch (NoSuchFieldError e8) {
            }
            try {
                $SwitchMap$com$getpebble$android$main$fragment$FragmentMetaData$FragmentType[FragmentType.CONNECTION_MANAGER.ordinal()] = 9;
            } catch (NoSuchFieldError e9) {
            }
            try {
                $SwitchMap$com$getpebble$android$main$fragment$FragmentMetaData$FragmentType[FragmentType.NOTIFICATION.ordinal()] = 10;
            } catch (NoSuchFieldError e10) {
            }
            try {
                $SwitchMap$com$getpebble$android$main$fragment$FragmentMetaData$FragmentType[FragmentType.NO_NETWORK_CONNECTION.ordinal()] = 11;
            } catch (NoSuchFieldError e11) {
            }
        }
    }

    public static class FragmentData {
        private int mActionBarColor;
        private int mActionBarIcon;
        private int mActionBarTitle;
        private Bundle mDefaultArgs;
        private boolean mNeedsInternetConnection;
        private int mStatusBarColor;
        private FragmentType mType;

        public FragmentData(FragmentType type, int actionBarColor, int statusBarColor, int actionBarIcon, int actionBarTitle, boolean needsInternetConnection) {
            this.mType = type;
            this.mActionBarColor = actionBarColor;
            this.mStatusBarColor = statusBarColor;
            this.mActionBarIcon = actionBarIcon;
            this.mActionBarTitle = actionBarTitle;
            this.mNeedsInternetConnection = needsInternetConnection;
        }

        public void setDefaultBundleArgs(Bundle args) {
            this.mDefaultArgs = args;
        }

        public FragmentType getType() {
            return this.mType;
        }

        public int getActionBarColor() {
            return this.mActionBarColor;
        }

        public int getActionBarIcon() {
            return this.mActionBarIcon;
        }

        public int getActionBarTitle() {
            return this.mActionBarTitle;
        }

        public int getStatusBarColor() {
            return this.mStatusBarColor;
        }

        public boolean needsInternetConnection() {
            return this.mNeedsInternetConnection;
        }

        public Fragment createFragment(Bundle args) {
            Fragment fragment;
            Bundle arguments;
            switch (AnonymousClass1.$SwitchMap$com$getpebble$android$main$fragment$FragmentMetaData$FragmentType[this.mType.ordinal()]) {
                case SMTPMessage.RETURN_FULL /*1*/:
                    fragment = new MyPebbleFragment();
                    break;
                case SMTPMessage.RETURN_HDRS /*2*/:
                    fragment = new AppStoreFragment();
                    break;
                case ListInfo.INDETERMINATE /*3*/:
                    fragment = new AppStoreFragment();
                    break;
                case SMTPMessage.NOTIFY_DELAY /*4*/:
                    fragment = new DeveloperFragment();
                    break;
                case R.styleable.WalletFragmentStyle_maskedWalletDetailsHeaderTextAppearance /*5*/:
                    fragment = new SettingsFragment();
                    break;
                case R.styleable.WalletFragmentStyle_maskedWalletDetailsBackground /*6*/:
                    fragment = new SupportFragment();
                    break;
                case R.styleable.WalletFragmentStyle_maskedWalletDetailsButtonTextAppearance /*7*/:
                    fragment = new AppStoreFragment();
                    break;
                case Response.NO /*8*/:
                    fragment = new AppStoreFragment();
                    break;
                case R.styleable.WalletFragmentStyle_maskedWalletDetailsLogoTextColor /*9*/:
                    fragment = new ConnectionManagerFragment();
                    break;
                case R.styleable.WalletFragmentStyle_maskedWalletDetailsLogoImageType /*10*/:
                    fragment = new NotificationSettingsFragment();
                    break;
                case R.styleable.MapAttrs_uiZoomGestures /*11*/:
                    fragment = new NoConnectivityFragment();
                    break;
                default:
                    throw new IllegalStateException("Unable to create a fragment for type: " + this.mType);
            }
            if (args == null) {
                arguments = this.mDefaultArgs;
            } else {
                arguments = args;
            }
            if (arguments == null) {
                arguments = new Bundle();
            }
            arguments.putInt("extra_fragment_type", this.mType.ordinal());
            fragment.setArguments(arguments);
            return fragment;
        }
    }

    public enum FragmentType {
        MY_PEBBLE,
        NOTIFICATION,
        APP_STORE_FACES,
        APP_STORE_APPS,
        DEVELOPER,
        SETTINGS,
        SUPPORT,
        APP_STORE_APPLICATION,
        APP_STORE_DEVELOPER,
        CONNECTION_MANAGER,
        NO_NETWORK_CONNECTION
    }

    public static FragmentData getFragmentDataByType(FragmentType type) {
        checkOnUiThread();
        if (sDataByType == null) {
            initDataByType();
        }
        return (FragmentData) sDataByType.get(type);
    }

    public static FragmentData getFragmentDataForDrawer(int drawerIndex) {
        checkOnUiThread();
        if (sDataByDrawerIndex == null) {
            initDataByDrawerIndex();
        }
        return (FragmentData) sDataByDrawerIndex.get(drawerIndex);
    }

    public static int getDrawerCount() {
        return sDataByDrawerIndex.size();
    }

    private static void initDataByType() {
        sDataByType = new HashMap();
        sDataByType.put(FragmentType.MY_PEBBLE, new FragmentData(FragmentType.MY_PEBBLE, R.color.actionbar_bg, R.color.statusbar_bg, R.drawable.ic_drawer_mypebble, R.string.drawer_title_mypebble, false));
        sDataByType.put(FragmentType.NOTIFICATION, new FragmentData(FragmentType.NOTIFICATION, R.color.orange_actionbar_color, R.color.orange_statusbar_color, R.drawable.ic_drawer_notification, R.string.drawer_title_notifications, false));
        FragmentData facesFragmentData = new FragmentData(FragmentType.APP_STORE_FACES, R.color.orange_actionbar_color, R.color.orange_statusbar_color, R.drawable.ic_drawer_faces, R.string.drawer_title_watchfaces, true);
        Bundle facesArgs = new Bundle();
        facesArgs.putInt("extra_store_type", StoreType.WATCH_FACES.ordinal());
        facesFragmentData.setDefaultBundleArgs(facesArgs);
        sDataByType.put(FragmentType.APP_STORE_FACES, facesFragmentData);
        FragmentData appsFragmentData = new FragmentData(FragmentType.APP_STORE_APPS, R.color.orange_actionbar_color, R.color.orange_statusbar_color, R.drawable.ic_drawer_apps, R.string.drawer_title_watchapps, true);
        Bundle appsArgs = new Bundle();
        appsArgs.putInt("extra_store_type", StoreType.WATCH_APPS.ordinal());
        appsFragmentData.setDefaultBundleArgs(appsArgs);
        sDataByType.put(FragmentType.APP_STORE_APPS, appsFragmentData);
        sDataByType.put(FragmentType.DEVELOPER, new FragmentData(FragmentType.DEVELOPER, R.color.orange_actionbar_color, R.color.orange_statusbar_color, R.drawable.ic_drawer_developer, R.string.drawer_title_developer, false));
        sDataByType.put(FragmentType.SETTINGS, new FragmentData(FragmentType.SETTINGS, R.color.orange_actionbar_color, R.color.orange_statusbar_color, R.drawable.ic_drawer_settings, R.string.drawer_title_settings, false));
        sDataByType.put(FragmentType.SUPPORT, new FragmentData(FragmentType.SUPPORT, R.color.orange_actionbar_color, R.color.orange_statusbar_color, R.drawable.ic_drawer_support, R.string.drawer_title_support, false));
        sDataByType.put(FragmentType.APP_STORE_APPLICATION, new FragmentData(FragmentType.APP_STORE_APPLICATION, R.color.orange_actionbar_color, R.color.orange_statusbar_color, R.drawable.ic_drawer_mypebble, R.string.app_store_app, true));
        sDataByType.put(FragmentType.APP_STORE_DEVELOPER, new FragmentData(FragmentType.APP_STORE_DEVELOPER, R.color.orange_actionbar_color, R.color.orange_statusbar_color, R.drawable.ic_drawer_mypebble, R.string.app_store_developer, true));
        sDataByType.put(FragmentType.CONNECTION_MANAGER, new FragmentData(FragmentType.CONNECTION_MANAGER, R.color.actionbar_bg, R.color.statusbar_bg, R.drawable.ic_drawer_mypebble, R.string.connection_manager_title, false));
        sDataByType.put(FragmentType.NO_NETWORK_CONNECTION, new FragmentData(FragmentType.NO_NETWORK_CONNECTION, R.color.actionbar_bg, R.color.statusbar_bg, R.drawable.ic_drawer_mypebble, R.string.no_internet_connection, false));
    }

    private static void initDataByDrawerIndex() {
        sDataByDrawerIndex = new ArrayList(6);
        sDataByDrawerIndex.add(getFragmentDataByType(FragmentType.MY_PEBBLE));
        sDataByDrawerIndex.add(getFragmentDataByType(FragmentType.NOTIFICATION));
        sDataByDrawerIndex.add(getFragmentDataByType(FragmentType.APP_STORE_FACES));
        sDataByDrawerIndex.add(getFragmentDataByType(FragmentType.APP_STORE_APPS));
        sDataByDrawerIndex.add(getFragmentDataByType(FragmentType.DEVELOPER));
        sDataByDrawerIndex.add(getFragmentDataByType(FragmentType.SETTINGS));
        sDataByDrawerIndex.add(getFragmentDataByType(FragmentType.SUPPORT));
    }

    public static void addDeveloperToDrawer() {
        checkOnUiThread();
        if (sDataByDrawerIndex == null) {
            initDataByDrawerIndex();
        }
        FragmentData developerData = getFragmentDataByType(FragmentType.DEVELOPER);
        if (!sDataByDrawerIndex.contains(developerData)) {
            sDataByDrawerIndex.add(DEVELOPER_DRAWER_INDEX, developerData);
        }
    }

    public static void removeDeveloperFromDrawer() {
        checkOnUiThread();
        if (sDataByDrawerIndex == null) {
            initDataByDrawerIndex();
        }
        sDataByDrawerIndex.remove(getFragmentDataByType(FragmentType.DEVELOPER));
    }

    public static FragmentType getFragmentType(Fragment currentFragment) {
        if (currentFragment == null) {
            return null;
        }
        Bundle args = currentFragment.getArguments();
        if (args == null || !args.containsKey("extra_fragment_type")) {
            return null;
        }
        return FragmentType.values()[args.getInt("extra_fragment_type")];
    }

    private static void checkOnUiThread() {
        if (!Looper.myLooper().equals(Looper.getMainLooper())) {
            throw new IllegalStateException("Cannot call FragmentMetaData from a non-UI thread.");
        }
    }
}
